home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 4838 / 4838.xpi / chrome / multipletab.jar / content / multipletab / lib / stopRendering.js < prev    next >
Text File  |  2010-02-03  |  3KB  |  132 lines

  1. /*
  2.  Stop Rendering Library
  3.  
  4.  Usage:
  5.    window['piro.sakura.ne.jp'].stopRendering.stop();
  6.    // do something
  7.    window['piro.sakura.ne.jp'].stopRendering.start();
  8.  
  9.  lisence: The MIT License, Copyright (c) 2009-2010 SHIMODA "Piro" Hiroshi
  10.    http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/license.txt
  11.  original:
  12.    http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/stopRendering.js
  13. */
  14. (function() {
  15.     const currentRevision = 3;
  16.  
  17.     if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {};
  18.  
  19.     var loadedRevision = 'stopRendering' in window['piro.sakura.ne.jp'] ?
  20.             window['piro.sakura.ne.jp'].stopRendering.revision :
  21.             0 ;
  22.     if (loadedRevision && loadedRevision > currentRevision) {
  23.         return;
  24.     }
  25.  
  26.     if (loadedRevision &&
  27.         'destroy' in window['piro.sakura.ne.jp'].stopRendering)
  28.         window['piro.sakura.ne.jp'].stopRendering.destroy();
  29.  
  30.     const Ci = Components.interfaces;
  31.  
  32.     window['piro.sakura.ne.jp'].stopRendering = {
  33.         revision : currentRevision,
  34.  
  35.         _stopLevel : 0,
  36.  
  37.         get baswWindow()
  38.         {
  39.             return window.top
  40.                     .QueryInterface(Ci.nsIInterfaceRequestor)
  41.                     .getInterface(Ci.nsIWebNavigation)
  42.                     .QueryInterface(Ci.nsIDocShell)
  43.                     .QueryInterface(Ci.nsIBaseWindow);
  44.         },
  45.  
  46.         stop : function()
  47.         {
  48.             if (this._stopLevel == 0) {
  49.                 this.baswWindow.setPosition(window.top.innerWidth * 3, window.top.innerHeight * 3);
  50.             }
  51.             this._stopLevel++;
  52.         },
  53.  
  54.         start : function()
  55.         {
  56.             this._stopLevel--;
  57.             if (this._stopLevel > 0)
  58.                 return;
  59.  
  60.             this._stopLevel = 0;
  61.             this.baswWindow.setPosition(0, 0);
  62.  
  63.             this._popups.forEach(function(aPopup, aIndex) {
  64.                 if (aPopup.state != 'open') return;
  65.                 var w = aPopup.boxObject.width;
  66.                 var h = aPopup.boxObject.height;
  67.                 aPopup.sizeTo(w, h-1);
  68.                 aPopup.sizeTo(w, h);
  69.             }, this);
  70.         },
  71.  
  72.         onResize : function(aEvent)
  73.         {
  74.             if (aEvent.target != window || !this._stopLevel)
  75.                 return;
  76.  
  77.             this._stopLevel = 0;
  78.             this.start();
  79.         },
  80.  
  81.  
  82.         handleEvent : function(aEvent)
  83.         {
  84.             switch (aEvent.type)
  85.             {
  86.                 case 'unload':
  87.                     this.destroy();
  88.                     return;
  89.  
  90.                 case 'resize':
  91.                     this.onResize(aEvent);
  92.                     return;
  93.  
  94.                 case 'popupshown':
  95.                     let (index = this._popups.indexOf(aEvent.originalTarget)) {
  96.                         if (index < 0)
  97.                             this._popups.push(aEvent.originalTarget);
  98.                     }
  99.                     return;
  100.  
  101.                 case 'popuphidden':
  102.                     let (index = this._popups.indexOf(aEvent.originalTarget)) {
  103.                         if (index > -1)
  104.                             this._popups.splice(index, 1);
  105.                     }
  106.                     return;
  107.             }
  108.         },
  109.  
  110.         init : function()
  111.         {
  112.             this._popups = [];
  113.             window.addEventListener('resize', this, false);
  114.             window.addEventListener('popupshown', this, false);
  115.             window.addEventListener('popuphidden', this, false);
  116.             window.addEventListener('unload', this, false);
  117.         },
  118.  
  119.         destroy : function()
  120.         {
  121.             this._popups = [];
  122.             window.removeEventListener('resize', this, false);
  123.             window.removeEventListener('popupshown', this, false);
  124.             window.removeEventListener('popuphidden', this, false);
  125.             window.removeEventListener('unload', this, false);
  126.         }
  127.  
  128.     };
  129.  
  130.     window['piro.sakura.ne.jp'].stopRendering.init();
  131. })();
  132.